水無瀬の部屋 > Programming > sample > exe2ico > exe2ico.cpp |
---|
1: //*********************************************************
2: // プロジェクト: exe2ico
3: // ファイル名: exe2ico.cpp
4: //*********************************************************
5: #include "exe2ico.h"
6: #include "exe2rsrc.h"
7: #include "exe2riff.h"
8: #include "rsrc2ico.h"
9: #include "rsrc2bmp.h"
10: #include "rsrc2cur.h"
11: #include "cmdline.h"
12: #include "instdlg.h" //
13: #include "util.h"
14: #include "res.h"
15: #include <workthrd/traythrd.h>
16: #include <misc/pathargv.h>
17:
18:
19: //---------------------------------------------------------
20: // マクロ定数 の 定義
21: //---------------------------------------------------------
22: //
23: #define MUTEX_INSTALLDLG ( "exe2ico.InstallDlg" )
24: //
25: #define MODE_EXE2ICO ( 1 ) //
26: #define MODE_INSTALL ( 2 ) // インストール
27: //
28: #define EXT_ICO ".ico"
29: #define EXT_CUR ".cur"
30: #define EXT_BMP ".bmp"
31: //
32: #define WAIT_MESSAGE "exe2ico が作業中です"
33:
34:
35: //---------------------------------------------------------
36: // 構造体 の 宣言
37: //---------------------------------------------------------
38: // THREADPARAM_tag
39: typedef struct THREADPARAM_tag
40: {
41: DWORD flags;
42: int argc;
43: char **argv;
44: } THREADPARAM_t;
45:
46:
47: //---------------------------------------------------------
48: // ファイルスコープ関数 の 宣言
49: //---------------------------------------------------------
50: static int GetApplicationMode( int argc, char **argv );
51: static int CommandLineApplicationMainProc( HINSTANCE hInstance, int argc, char **argv );
52: static int ApplicationInstallMainProc( HINSTANCE hInstance, int argc, char **argv );
53:
54:
55: //*********************************************************
56: // ApplicationMainProc
57: //*********************************************************
58: int
59: ApplicationMainProc
60: (
61: HINSTANCE hInstance,
62: int argc,
63: char **argv
64: )
65: {
66: // パラメタの仮定
67: ASSERT( IsValidInstanceHandle( hInstance ) );
68: ASSERT( IsValidArgcArgv( argc, argv ) );
69: ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
70:
71: //
72: const int mode = GetApplicationMode( argc, argv );
73: switch( mode )
74: {
75: default: return EXIT_FAILURE;
76: case MODE_EXE2ICO: return CommandLineApplicationMainProc( hInstance, argc, argv );
77: case MODE_INSTALL: return ApplicationInstallMainProc( hInstance, argc, argv );
78: }
79: }//ApplicationMainProc
80:
81:
82: //******************************************************************************************************************
83: // private
84: //******************************************************************************************************************
85: //*********************************************************
86: // GetApplicationMode
87: //*********************************************************
88: static
89: int
90: GetApplicationMode
91: (
92: int argc,
93: char **argv
94: )
95: {
96: // パラメタの仮定
97: ASSERT( IsValidArgcArgv( argc, argv ) );
98: ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
99:
100: // 引数が無ければ 設定 モード
101: return (1 < argc) ? MODE_EXE2ICO : MODE_INSTALL ;
102: }//GetApplicationMode
103:
104:
105: //******************************************************************************************************************
106: // private - MODE_INSTALL
107: //******************************************************************************************************************
108: //*********************************************************
109: // ApplicationInstallMainProc
110: //*********************************************************
111: static
112: int
113: ApplicationInstallMainProc
114: (
115: HINSTANCE hInstance,
116: int argc,
117: char **argv
118: )
119: {
120: // パラメタの仮定
121: ASSERT( IsValidInstanceHandle( hInstance ) );
122: ASSERT( IsValidArgcArgv( argc, argv ) );
123: ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
124:
125: //
126: HANDLE hMutex = CreateMutexOnce( MUTEX_INSTALLDLG );
127: if ( hMutex )
128: {
129: InstallDlg( HWND_DESKTOP );
130: VERIFY( CloseHandle( hMutex ) );
131: }
132:
133: return EXIT_SUCCESS;
134: }//ApplicationInstallMainProc
135:
136:
137: //******************************************************************************************************************
138: // private - MODE_EXE2ICO
139: //******************************************************************************************************************
140: static DWORD WINAPI WorkerThreadProc( thread_t *thread, void *param );
141:
142:
143: //*********************************************************
144: // CommandLineApplicationMainProc
145: //*********************************************************
146: static
147: int
148: CommandLineApplicationMainProc
149: (
150: HINSTANCE hInstance,
151: int argc,
152: char **argv
153: )
154: {
155: // パラメタの仮定
156: ASSERT( IsValidInstanceHandle( hInstance ) );
157: ASSERT( IsValidArgcArgv( argc, argv ) );
158: ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
159:
160:
161: // コマンドライン引数の取得
162: const DWORD flags = get_cmdline_option( argc, argv );
163:
164: //
165: int count;
166: char **paths = GetPathArgcArgv( &count, argc - 1, argv + 1 );
167: if ( paths )
168: {
169: //
170: THREADPARAM_t param;
171: param.flags = flags;
172: param.argc = count;
173: param.argv = paths;
174:
175: HICON hIcon = LoadIconImage( hInstance, MAKEINTRESOURCE( IDI_ICON ), 16, 16, 0 );
176: RunOnTrayIcon( WorkerThreadProc, ¶m, hIcon, WAIT_MESSAGE );
177:
178: VERIFY( ReleasePathArgcArgv( count, paths ) );
179: }
180:
181: return EXIT_SUCCESS;
182: }//CommandLineApplicationMainProc
183:
184:
185: //******************************************************************************************************************
186: // private
187: //******************************************************************************************************************
188: //*********************************************************
189: // WorkerThreadProc
190: //*********************************************************
191: static
192: DWORD // スレッドの終了コード
193: WINAPI
194: WorkerThreadProc
195: (
196: thread_t *thread,
197: void *pThreadParam
198: )
199: {
200: // パラメタの仮定
201: ASSERT( IsValidReadPtr( (THREADPARAM_t *)pThreadParam, sizeof( THREADPARAM_t ) ) );
202:
203:
204: //
205: VERIFY( S_OK == CoInitialize( null ) );
206:
207: //
208: const THREADPARAM_t *param = static_cast<THREADPARAM_t *>( pThreadParam );
209: ASSERT( IsValidArgcArgv( param->argc, param->argv ) );
210:
211: // 処理
212: {for( int i = 0; (i < param->argc) && !IsWorkerThreadCanceled( thread ); ++i )
213: {
214: if ( IsPathFile( param->argv[ i ] ) )
215: {
216: const struct
217: {
218: DWORD flag;
219: const char *type;
220: const char *ext;
221: rsrc2file_t rsrc2file;
222: }
223: pair[] =
224: {
225: { FLAG_NOICO, RT_GROUP_ICON, EXT_ICO, rsrc2ico },
226: { FLAG_NOCUR, RT_GROUP_CURSOR, EXT_CUR, rsrc2cur },
227: { FLAG_NOBMP, RT_BITMAP, EXT_BMP, rsrc2bmp },
228: };
229:
230: {for( int j = 0; (j < numof(pair)) && !IsWorkerThreadCanceled( thread ); ++j )
231: {
232: if ( pair[ j ].flag != (param->flags & pair[ j ].flag) )
233: {
234: exe2rsrc( param->argv[ i ], pair[ j ].type, pair[ j ].ext, pair[ j ].rsrc2file );
235: }
236: }}
237:
238: if ( !IsWorkerThreadCanceled( thread ) )
239: {
240: if ( FLAG_NORIFF != (param->flags & FLAG_NORIFF) )
241: {
242: exe2riff( param->argv[ i ], param->flags );
243: }
244: }
245: }
246: }}
247:
248: //
249: CoUninitialize();
250:
251: return 0; // 終了
252: }//WorkerThreadProc
253:
254:
255: //** end **
参照:
水無瀬の部屋 > sample > exe2ico > exe2ico.cpp |
---|
このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/exe2ico/exe2ico_cpp.shtml
>> Amazon.co.jp 『たまゆら童子』 へ
>> 楽天ブックス 『たまゆら童子』 へ